/* GSStocksProcesser.java
 *
 * Project/Product: JZCG-XMBUS
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   peng.ning	2008-8-26	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.business;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import com.hitrust.gs.bean.GSBalanceMsgBean;
import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSOrganizationBean;
import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.bean.GSStocksBean;
import com.hitrust.gs.bean.GSStocksDetailBean;
import com.hitrust.gs.dao.GSBalanceMsgDAO;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.dao.GSOrderDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.dao.GSOrganizationDAO;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.dao.GsStocksDao;
import com.hitrust.gs.form.GSStocksBanlanceForm;
import com.hitrust.gs.form.GSStocksDetailForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseProcesser;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.vo.GSBalanceInfoVO;
import com.hitrust.gs.vo.GSStocksVO;

public class GSStocksProcesser implements GSBaseProcesser {
    private GsStocksDao sdao=new GsStocksDao();
    public ArrayList getStocksResult(GSStocksVO svo)throws GSException{
        return sdao.getStocksResult(svo);
    }
    public int getStocksResultCount(GSStocksVO svo) throws GSException{
        return sdao.getStocksResultCount(svo);
    }
    public ArrayList getStocksResultByPage(GSStocksVO svo,int pageNo,int pageSize) throws GSException{
        return sdao.getStocksResultByPage(svo, pageNo, pageSize);
    }
    public ArrayList getStocksResultByPage3(GSStocksVO svo,int pageNo,int pageSize) throws GSException{
        return sdao.getStocksResultByPage3(svo, pageNo, pageSize);
    }
    public int getStocksResultCount3(GSStocksVO svo) throws GSException{
        return sdao.getStocksResultCount3(svo);
    }
    public int getStocksResultCount2(GSStocksVO svo) throws GSException{
        return sdao.getStocksResultCount2(svo);
    }
    public ArrayList getStocksResultByPage2(GSStocksVO svo,int pageNo,int pageSize) throws GSException{
        return sdao.getStocksResultByPage2(svo, pageNo, pageSize);
    }
    public int getStocksResultCount(String[] str)throws GSException{
        return sdao.getStocksDetailBalanceResultRow(str);
    }
    public void savestocks(GSStocksVO svo,ArrayList ar) throws GSException{
        int count=sdao.getStocksCount(svo.gs_stocks_id);
        if(count>0){
            throw new GSException("领用单编号已存在");
        }
        sdao.save(svo, ar);
    }
    public ArrayList getBalanceYes(String[] str) throws GSException{
        ArrayList ar=sdao.getStocksDetailBalanceResult(str);
        return ar;
    }
    public ArrayList getBalanceYes(String[] str,int pageNo,int pageSize) throws GSException{
        ArrayList ar=sdao.getStocksDetailBalanceResult(str,pageNo,pageSize);
        return ar;
    }
    public GSStocksBean getStocksBySid(String sid) throws GSException{
        return sdao.getStocksResultBySid(sid);
    }
    public ArrayList getStocksDetailBySid(String sid) throws GSException{
        return sdao.getStocksDetailResultBySid(sid);
    }
    public GSStocksDetailBean getStocksDetailByDid(String did) throws GSException{
        return sdao.getStocksDetailResultByDid(did);
    }
    public boolean getstocksbyid(String sid) throws GSException{
        int count=sdao.getStocksCount(sid);
        boolean bl=false;
        if (count<=0) {
            bl=true;
        }
        return bl;
    }
    public ArrayList getStocksDetailByMonthProvid(String[] str) throws GSException{
        return sdao.getStocksDetailByMonthProvid(str);
    }
    public ArrayList getStocksDetailByMonthProvidpage(String[] str,int pageNo,int pageSize) throws GSException{
        return sdao.getStocksDetailByMonthProvidpage(str,pageNo,pageSize);
    }
    private GSBalanceMsgDAO mdao=new GSBalanceMsgDAO();
    public GSBalanceMsgBean getbanlancemsg(String dep,String ym) throws GSException{
       ArrayList ar= mdao.queryBalanceInfo(dep, ym);
       GSBalanceMsgBean mb=null;
       if (ar.size()>0) {
           mb=(GSBalanceMsgBean) ar.get(0);
       }
       return mb;
    }
  //纳入结算
    public boolean balanceStocksSelect(GSStocksBanlanceForm stform) throws GSException{
      //0:取得当前操作员信息
        GSOperatorBean tOperBean = (GSOperatorBean)stform.getSession().getAttribute(GSBaseConstants.LOGIN);
        String tEndDate = stform.getBalanceEndDate();
        tEndDate = tEndDate.substring(0,4) + tEndDate.substring(5,7) + tEndDate.substring(8,10);
        //1:计算当前结算月
        String tEndDate1 = tEndDate.substring(0,6);
        //2:取得当前所有被选明细信息
        String[] indexs = stform.getCheck();
        boolean tFlag = false;
        tFlag=sdao.doBalanceRecord(indexs, tEndDate1, tOperBean, new String[]{stform.getBalanceStrDate(),stform.getBalanceEndDate()});
        return tFlag;
    }
    //暂不结算
    public boolean balanceStocksBack(String dep,String ym,GSOperatorBean operbean,String[] indexs) throws GSException{
        boolean bl=sdao.stocksBanlanceBack(dep, ym, operbean, indexs);
        return bl;
    }
    //作废
    public boolean balanceStocksDel(String dep,String ym,GSOperatorBean operbean,String[] indexs,String re) throws GSException{
        boolean bl=sdao.stocksBanlanceDel(dep, ym, operbean, indexs,re);
        return bl;
    }
    //调整
    public boolean balanceStocksUpdate(String dep,String ym,GSOperatorBean operbean,String[] indexs,String[] str) throws GSException{
        boolean bl=sdao.stocksBanlanceUpdate(dep, ym, operbean, indexs, str);
        return bl;
    }
    //查询调整
    public boolean balanceStocksUpdate(GSOperatorBean operbean,String[] indexs,String[] str) throws GSException{
        boolean bl=sdao.stocksBanlanceUpdate(operbean, indexs, str);
        return bl;
    }
  //查询作废
    public boolean balanceStocksDel(GSOperatorBean operbean,String[] indexs) throws GSException{
        boolean bl=sdao.stocksBanlanceDel(operbean, indexs);
        return bl;
    }
    public boolean updateorgprovstate() throws GSException{
        boolean bl=sdao.updateorgprov();
        return bl;
    }
}
